<template>
	<view style="padding: 20rpx 35rpx;">
		<text class="sm-text">为保障您的资金安全,更好的使用云赚提现服务,需要您提供真实身份证上的资料完成实名认证</text>
		<view class="row input" style="">
			<text style="margin-right: 30rpx;">真实姓名</text>
			<input :disabled="identityCardStatus" style="width: 400rpx;" type="text" v-model="userInfo.realName" placeholder="请输入您的真实姓名" />
		</view>
		<view class="row input" style="">
			<text style="margin-right: 30rpx;">身份证号</text>
			<input :disabled="identityCardStatus" style="width: 400rpx;" type="text" v-model="userInfo.idCard" placeholder="请输入您的身份证号码" />
		</view>
		<view style="margin-top: 50rpx;color: #ff0000;" class="sm-text">实名信息绑定后将不可更换,实名信息将会与你的提现相关,有误将导致提现失败</view>
		<view style="margin: 50rpx auto;" @click="submit()" v-if="!identityCardStatus" class="global-button">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:{
					idCard:"",
					realName:""
				},
				identityCardStatus:true,
				submitAddress:false
			};
		},
		onShow() {
			this.verificationIdentityCard();
		},
		methods:{
			identityCardDispose(idCard){
				if (null != idCard && idCard != undefined) {
					var pat = /(\d{3})\d*(\d{2})/;
					return idCard.replace(pat, '$1****************$2');
				} else {
					return "";
				}
			},
			//查询是否实名认证
			verificationIdentityCard(){
				this.$util.doPostJson("/wx/saveSFZ", {}, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						console.log("身份证验证",res.data)
						if(!res.data.data){
							this.identityCardStatus = false
						}else {
							this.userInfo = res.data.data
							this.userInfo.idCard = this.identityCardDispose(this.userInfo.idCard)
						}
					}else {
						
					}
				}).catch(error => {
					console.log(error)
				})
			},
			IsCard(str) {
				 var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				 return reg.test(str);
			},
			submit(){
				if(this.submitAddress){
					return
				}
				if(!this.userInfo.realName){
					this.$util.showInfoToast("请输入你的真实姓名")
					return
				}
				if(!this.IsCard(this.userInfo.idCard)){
					this.$util.showInfoToast("请输入正确格式的身份证号码")
					return
				}
				this.submitAddress = true
				this.$util.doPostJson("/wx/idcardAuthentication", this.userInfo, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						console.log("身份证验证",res.data)
						if(res.data.data){
							this.identityCardStatus = true
							this.$util.showInfoToast("认证成功")
							this.userInfo.idCard = this.identityCardDispose(this.userInfo.idCard)
						}
						this.submitAddress = false
					}
				}).catch(error => {
					console.log(error)
				})
			}
		}
	}
</script>

<style lang="scss">
	.row{
	}
	
	.sm-text{
		font-size: 30rpx;
		color: #979797;
	}
	
	.input{
		padding: 35rpx 0rpx;
		align-items: center;
		border-bottom: solid 1rpx #EEEEEE;
	}
</style>
